var _PUB_imgerror_exist;
var _SITE_ID;
var _INCLIENT = '';
var _USER_TYPE = '';
$(function() {
    _INCLIENT = $.getURLParam('inclient') || '';
    $('body').on('error_evt', function(e, parentElement) {
        if (typeof _PUB_imgerror_exist === 'undefined') {
            $('<img>').attr('src', 'wdk?action=wdk.pub&method=attachment_download&fileid=img_error').on({
                'load': function() {
                    _PUB_imgerror_exist = true;

                    $(parentElement).find('img').off().on('error', function() {
                        $(this).attr('src', 'wdk?action=wdk.pub&method=attachment_download&fileid=img_error');
                    });
                },
                'error': function() {
                    _PUB_imgerror_exist = false;
                }
            });

        } else if (_PUB_imgerror_exist) {
            $(parentElement).find('img').off().on('error', function() {
                $(this).attr('src', 'wdk?action=wdk.pub&method=attachment_download&fileid=img_error');
            });
        }
    });
});

$.extend({
    getClientInfo: function(callback) {
        // 加载FingerprintJS脚本并获取终端信息
        loadScript('ecw/component/buy_main/iife.min.js', function() {
            FingerprintJS.load().then(function(fp) {
                fp.get().then(function(result) {
                    _buy_main_userAgent = result.visitorId;

                    // 获取终端信息（包括IP，浏览器信息）
                    $.cuajax({
                        url: _ECW_URL2,
                        data: {},
                        success: function(result) {
                            var jres = $.str2json(result);
                            var ip = '';
                            if (jres.code == '1') {
                                ip = jres.result || '';
                            }
                            callback && callback({
                                ip: ip,
                                userAgent: _buy_main_userAgent
                            });
                        },
                        error: function(result) {
                            callback && callback({
                                ip: '',
                                userAgent: _buy_main_userAgent
                            });
                        }
                    });
                });
            });
        });
    },
    getPubPara: function(para_code, callback) {
        // 获取投诉电话、客服热线
        $.cuajax({
            url: _PUB_URL2,
            data: {
                _SRVNAME: 'service.ecw.pub.ecwpara',
                _SRVMETHOD: 'getPara',
                _DATA: $.json2str({
                    manage_unit_uuid: $.getLoginUser().manage_unit_uuid,
                    para_code: para_code
                })
            },
            success: function(result) {
                var jres = $.str2json(result);

                if (jres.code == '1') {
                    callback && callback(jres.para_info);
                } else {
                    alert(jres.desc);
                }
            },
            error: function(result) {
                alert('网络错误！result=' + result);
            }
        })
    },
    getColumnSetup: function(app_code, module_code, callback) {
        // 按应用模块取管理单元栏目配置
        $.cuajax({
            url: _PUB_URL2,
            data: {
                _SRVNAME: 'service.ecw.cms.setup',
                _SRVMETHOD: 'getColumnSetup',
                _DATA: $.json2str({
                    manage_unit_uuid: $.getLoginUser().manage_unit_uuid,
                    app_code: app_code,
                    module_code: module_code
                })
            },
            success: function(result) {
                var jres = $.str2json(result);

                if (jres.code == '1') {
                    callback && callback(jres.column_infos, jres.module_info);
                } else {
                    alert(jres.desc);
                }
            },
            error: function(result) {
                alert('网络错误！result=' + result);
            }
        })
    },
    //由系统调用，再页面组件加载之前调用
    page_init_before: function(page_id) {}
        //由系统调用，再页面组件加载之后调用
        ,
    page_init_after: function(page_id) {
            var _column_uuid = '';
            // 获取栏目配置信息
            if (page_id == "page_ntmbuyer_index") { // 非烟商城
                $.getColumnSetup('NTM', 'NTM_INDEX_TCGG', function(column_infos, module_info) {
                    openPopnotice(column_infos, module_info);
                });
            } else if (page_id == "page_index") { // 卷烟商城
                // 卷烟商城
                //openPopContract();
                //许可证过期
                cust_license_expire();
                $.getColumnSetup('ECW', 'ECW_INDEX_TCGG', function(column_infos, module_info) {
                    openPopnotice(column_infos, module_info);
                });
            }

            function openPopnotice(column_infos, module_info) {
                var column = column_infos[0] || {};
                var _sessionuser = $.getLoginUser();
                var order_bussiness_mode = _sessionuser.order_bussiness_mode;
                var org_uuid = "";
                if (order_bussiness_mode === 'mode_tianjin') {
                    org_uuid = _sessionuser.county_uuid;
                } else {
                    org_uuid = _sessionuser.corp_uuid;
                }

                if (!column.column_uuid) {
                    return;
                }
                $.cuajax({
                    url: _PUB_URL2,
                    data: {
                        _SRVNAME: 'service.ecw.cms.main.v5',
                        _SRVMETHOD: 'queryUnReadPopupList',
                        _DATA: $.json2str({
                            user_info: {
                                account_id: _sessionuser.account_uuid,
                                personuuid: _sessionuser.cust_uuid,
                                manageunituuid: _sessionuser.manage_unit_uuid,
                                org_uuid: org_uuid
                            },
                            column_uuid: column.column_uuid,
                            search_fields: {
                                title: '',
                                show_time_start: '',
                                show_time_end: ''
                            },
                            result_fields: '',
                            order_fields: ''
                        })
                    },
                    success: function(result) {
                        var jres = $.str2json(result);
                        var jrows = jres.result;

                        if (jres.code == '1' && jrows.length != 0) {
                            var _width = $(window).width();
                            var _height = $(window).height();
                            _height = _height > 520 ? 520 : _height;
                            _width = _width > 700 ? 700 : _width;
                            $.dialog_open({
                                page: 'page_popnotice',
                                width: _width + 'px',
                                height: _height + 'px',
                                closeBtn: 0,
                                title: ['', 'overflow:visible'],
                                page_param: 'column_uuid=' + column.column_uuid
                            });
                        }
                    },
                    error: function(result) {
                        alert('网络错误！result=' + result);
                    }
                })
            }

            //新户入网协议
            function openPopContract() {
                var _sessionuser = $.getLoginUser();
                $.cuajax({
                    url: _PUB_URL2,
                    data: {
                        _SRVNAME: 'service.crm.cst.contract.v5',
                        _SRVMETHOD: 'queryUnReadContract',
                        _DATA: $.json2str({
                            op_account_uuid: _sessionuser.account_uuid,
                            op_person_uuid: _sessionuser.cust_uuid,
                            op_person_name: "",
                            manageunituuid: _sessionuser.manage_unit_uuid,
                            input_obj: {
                                contract_type_code: "01"
                            }
                        })
                    },
                    success: function(result) {
                        var jres = $.str2json(result);
                        var data = jres.result;
                        if (jres.code == '1' && data.length != 0) {
                            if (data.is_notice_contract == '1') {
                                //当前需要提示同意用户协议
                                var _width = $(window).width();
                                var _height = $(window).height();
                                _height = _height > 700 ? 700 : _height;
                                _width = _width > 1000 ? 1000 : _width;
                                $.dialog_open({
                                    page: 'page_popcontract',
                                    width: _width + 'px',
                                    height: _height + 'px',
                                    closeBtn: 0,
                                    title: ['', 'overflow:visible'],
                                    page_param: 'idx_contract_uuid=' + data.notice.uuid + '&contract_type_code=' + '01',
                                    onSubmit: function(result) {
                                        //隐私协议
                                        openConcealContract();
                                    }
                                });
                            } else {
                                openConcealContract();
                            }
                        }

                    },
                    error: function(result) {
                        alert('网络错误！result=' + result);
                    }
                })

            }

            //用户隐私协议
            function openConcealContract() {
                var _sessionuser = $.getLoginUser();
                $.cuajax({
                    url: _PUB_URL2,
                    data: {
                        _SRVNAME: 'service.crm.cst.contract.v5',
                        _SRVMETHOD: 'queryUnReadContract',
                        _DATA: $.json2str({
                            op_account_uuid: _sessionuser.account_uuid,
                            op_person_uuid: _sessionuser.cust_uuid,
                            op_person_name: "",
                            manageunituuid: _sessionuser.manage_unit_uuid,
                            input_obj: {
                                contract_type_code: "02"
                            }
                        })
                    },
                    success: function(result) {
                        var jres = $.str2json(result);
                        var data = jres.result;
                        if (jres.code == '1' && data.length != 0) {
                            if (data.is_notice_contract == '1') {
                                //当前需要提示同意用户协议
                                var _width = $(window).width();
                                var _height = $(window).height();
                                _height = _height > 700 ? 700 : _height;
                                _width = _width > 1000 ? 1000 : _width;
                                $.dialog_open({
                                    page: 'page_popcontract',
                                    width: _width + 'px',
                                    height: _height + 'px',
                                    closeBtn: 0,
                                    title: ['', 'overflow:visible'],
                                    page_param: 'idx_contract_uuid=' + data.notice.uuid + '&contract_type_code=' + '02',
                                    onSubmit: function(result) {
                                        isCustInNet()
                                    }
                                });
                            } else {
                                isCustInNet()
                            }
                        }

                    },
                    error: function(result) {
                        alert('网络错误！result=' + result);
                    }
                })

            }

            function isCustInNet() {
                //是否零售户入网
                $.cuajax({
                    url: _PUB_URL2,
                    data: {
                        _SRVNAME: 'service.tc.rtl.cache.v5',
                        _SRVMETHOD: 'getSysPara',
                        _DATA: $.json2str({
                            code: "is_cust_in_net",
                        })
                    },
                    success: function(result) {
                        var jres = $.str2json(result);
                        var data = jres.resultset;
                        if (jres.code == "1") {
                            console.log(data)
                            if (data.value == 1) {
                                getCustNetInStatusByCustUuid();
                            }
                        } else {
                            alert(jres.desc);
                        }
                    },
                    error: function(result) {
                        alert('网络错误！result=' + result);
                    }
                });
            }

            function getCustNetInStatusByCustUuid() {
                var _sessionuser = $.getLoginUser();
                $.cuajax({
                    url: _PUB_URL2,
                    data: {
                        _SRVNAME: 'service.uc.cst.custext.v5',
                        _SRVMETHOD: 'getCustNetInStatusByCustUuid',
                        _DATA: $.json2str({
                            manage_unit_uuid: _sessionuser.manage_unit_uuid,
                            cust_uuid: _sessionuser.cust_uuid
                        })
                    },
                    success: function(result) {
                        var jres = $.str2json(result);
                        var data = jres.result;
                        if (jres.code == '1' && data.length != 0) {
                            if (data.net_in_status == '0') {
                                var node_code = data.node_code;
                                if (!node_code || parseInt(node_code) < 4) {
                                    alert("抱歉，您还未完成入网操作，暂时无法订购卷烟，请联系客户经理处理。")
                                    return;
                                }
                                //当前需要提示同意用户协议
                                var _width = $(window).width();
                                var _height = $(window).height();
                                _height = 450;
                                _width = 700;
                                $.dialog_open({
                                    page: 'page_pop_in_net',
                                    width: _width + 'px',
                                    height: _height + 'px',
                                    closeBtn: 0,
                                    title: ['', 'overflow:visible'],
                                    page_param: '',
                                    onSubmit: function(result) {

                                    }
                                });
                            } else {}
                        }

                    },
                    error: function(result) {
                        alert('网络错误！result=' + result);
                    }
                })
            }

            //许可证过期
            function cust_license_expire() {
                var _sessionuser = $.getLoginUser();
                $.cuajax({
                    url: _PUB_URL2,
                    data: {
                        _SRVNAME: 'service.uc.cst.licenseexpire.v5',
                        _SRVMETHOD: 'notice_license_expire',
                        _DATA: $.json2str({
                            op_acc: _sessionuser.account_uuid,
                            cust_uuid: _sessionuser.cust_uuid
                        })
                    },
                    success: function(result) {
                        var jres = $.str2json(result);
                        if (jres.code == '1' && jres.notice == '1') {
                            //当前需要提示同意用户协议
                            var _width = $(window).width();
                            var _height = $(window).height();
                            _height = 450;
                            _width = 700;
                            $.dialog_open({
                                page: 'page_pop_license_expire',
                                width: _width + 'px',
                                height: _height + 'px',
                                closeBtn: 0,
                                title: ['', 'overflow:visible'],
                                page_param: '',
                                onSubmit: function(result) {

                                }
                            });
                        } else {
                            console.log("许可证过期" + jres.desc)
                        }

                    },
                    error: function(result) {
                        alert('网络错误！result=' + result);
                    }
                })

            }

        }

        ,
    setLoginUser: function(juser) {
        Cookies.set('wdk_user', Base64.encode($.json2str(juser)));
    },
    setHttpOnly: function(flag) {
        Cookies.set('HttpOnly', flag);
    },
    clearCookies: function() {
            Cookies.clear("wdk_user");
        }
        //获取sessionuser对象
        ,
    getLoginUser: function() {
            /*
            cust_uuid:客户标识
            cust_name:客户名称
            manage_unit_uuid:管理单元标识
            corp_uuid:市公司标识
            county_uuid:区县公司标识
            depart_uuid:市场部标识
            account_uuid:账号标识
            login_name:登陆账号

            /*
            var juser = new Object();
            juser.cust_uuid = '00000000000000000000000001000001';		//'客户标识'，也是person_uuid
            juser.cust_name = '客户名称';
            juser.manage_unit_uuid = '00000000000000000000000000000001';	//'管理单元标识'
            juser.corp_uuid = '00000000001389361289593_9710_201';	//'市公司标识'
            juser.county_uuid = '区县公司标识';
            juser.depart_uuid = '市场部标识';
            juser.account_uuid = '0000000000000000000zhuxiaowen_hz';	//'账号标识';
            juser.login_name = '登陆账号';
            */

            var strUser = Base64.decode(Cookies.get('wdk_user'));
            var juser = $.str2json(strUser);
            return juser;

        }
        //获取站点中文名
        ,
    getSiteName: function() {
            var _SITE_NAME = _SITE_ID;
            if (_SITE_ID == 'hangzhou') {
                _SITE_NAME = '杭州站';
            } else if (_SITE_ID == 'ningbo') {
                _SITE_NAME = '宁波站';
            } else if (_SITE_ID == 'wenzhou') {
                _SITE_NAME = '温州站';
            } else if (_SITE_ID == 'jiaxing') {
                _SITE_NAME = '嘉兴站';
            } else if (_SITE_ID == 'huzhou') {
                _SITE_NAME = '湖州站';
            } else if (_SITE_ID == 'shaoxing') {
                _SITE_NAME = '绍兴站';
            } else if (_SITE_ID == 'jinhua') {
                _SITE_NAME = '金华站';
            } else if (_SITE_ID == 'quzhou') {
                _SITE_NAME = '衢州站';
            } else if (_SITE_ID == 'lishui') {
                _SITE_NAME = '丽水站';
            } else if (_SITE_ID == 'taizhou') {
                _SITE_NAME = '台州站';
            } else if (_SITE_ID == 'zhoushan') {
                _SITE_NAME = '舟山站';
            }
            return _SITE_NAME;
        }
        //回到订货网站首页
        ,
    go_index: function() {
            $.getRoot().location.href = 'wdk?action=ecw.page&method=display&site_id=' + _SITE_ID + '&inclient=' + _INCLIENT + '&page_id=page_index';
        }
        //回到商家管理首页
        ,
    go_ntm_index: function() {
            $.getRoot().location.href = 'wdk?action=ecw.page&method=display&site_id=' + _SITE_ID + '&inclient=' + _INCLIENT + '&page_id=page_ntm_onsale';
        }
        //回到订货网站首页
        ,
    go_login: function() {
            $.getRoot().location.href = 'wdk?action=ecw.page&method=display&site_id=' + _SITE_ID + '&inclient=' + _INCLIENT + '&page_id=page_login';
        }
        //回到商家管理首页
        ,
    go_ntm_login: function() {
            $.getRoot().location.href = 'wdk?action=ecw.page&method=display&site_id=' + _SITE_ID + '&inclient=' + _INCLIENT + '&page_id=page_ntm_login';
        }
        //回到员工登录首页
        ,
    go_staff_login: function() {
        $.getRoot().location.href = 'wdk?action=ecw.page&method=display&site_id=' + _SITE_ID + '&inclient=' + _INCLIENT + '&page_id=page_staff_login';
    },
    go_wx_login: function() {
            $.getRoot().location.href = 'wdk?action=ecw.page&method=display&site_id=' + _SITE_ID + '&inclient=' + _INCLIENT + '&page_id=page_wx_login';
        }
        //是否在终端容器中运行
        ,
    is_in_client: function() {
            var is_in_client = false;

            //判断是否在指定的浏览器中允许，如果是的话则不在新页签中打开
            var ua = navigator.userAgent;
            //alert(ua);

            if (ua.indexOf("rv:24.0") > -1 && ua.indexOf("Gecko/ /24.0") > -1) {
                //Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/ /24.0
                is_in_client = true; //用友终端
            }
            if (is_in_client == false && ua.indexOf("Chrome/44.0.2403.119") > -1) {
                //Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.100 Safari/537.36
                //Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36
                //Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; SLCC2; .NET CLR 2.0.50727; .NET4.0C; .NET4.0E; .NET CLR 3.5.30729; .NET CLR 3.0.30729; rv:11.0) like Gecko
                is_in_client = true; //百富终端
            }
            if (is_in_client == false && _INCLIENT == '1') {
                is_in_client = true; //url上带了从终端访问的标志
            }

            return is_in_client;
        }
        //新开窗口打开页面
        //	page_open:function(page_id,page_param){
        //		if(!page_param){
        //			page_param = '';
        //		}else{
        //			page_param = '&'+page_param;
        //		}
        //		window.open('wdk?action=ecw.page&method=display&page_id='+page_id+page_param);
        //	}
        ,
    currentPage_open: function(page_id, page_param) {
        if (!page_param) {
            page_param = '';
        } else {
            page_param = '&' + page_param;
        }
        location.href = 'wdk?action=ecw.page&method=display&site_id=' + _SITE_ID + '&inclient=' + _INCLIENT + '&page_id=' + page_id + page_param;
    },
    page_open: function(page_id, page_param) {
            var is_in_client = $.is_in_client();

            if (!page_param) {
                page_param = '';
            } else {
                page_param = '&' + page_param;
            }

            var _url = 'wdk?action=ecw.page&method=display&site_id=' + _SITE_ID + '&inclient=' + _INCLIENT + '&page_id=' + page_id + page_param;

            if (is_in_client) {
                //在终端内运行
                $.getRoot().location.href = _url;
            } else {
                window.open(_url);
            }

        }
        //替换当前页面跳转到新页面
        ,
    page_redirect: function(page_id, page_param) {
        if (!page_param) {
            page_param = '';
        } else {
            page_param = '&' + page_param;
        }
        $.getRoot().location.href = 'wdk?action=ecw.page&method=display&site_id=' + _SITE_ID + '&inclient=' + _INCLIENT + '&page_id=' + page_id + page_param;
    },
    page_redirect_innewtab: function(page_id, page_param) {
            var is_in_client = $.is_in_client();

            if (is_in_client) {
                $.page_redirect(page_id, page_param);
            } else {
                if (!page_param) {
                    page_param = '';
                } else {
                    page_param = '&' + page_param;
                }

                var _url = 'wdk?action=ecw.page&method=display&site_id=' + _SITE_ID + '&inclient=' + _INCLIENT + '&page_id=' + page_id + page_param;

                window.open(_url);
            }
        }
        //弹出窗口
        //	实现思路如下：
        //		1、创建第一个蒙版图层，遮盖当前整个页面，透明度50%
        //		2、创建第二个图层，里面嵌入iframe
        //		3、注册回调方法
        //		4、将目标地址引入iframe，并将当前参数传递进去，用于回调使用
        ,
    dialog_open: function(jparam) {
            var _win_id = $.getUUID();
            var _page = jparam.page;
            var _url = jparam.url;
            var _closeBtn = jparam.closeBtn;
            var _move = jparam.move;

            if (!_move && (typeof _move !== 'boolean')) {
                _move = '.layui-layer-title';
            }
            if (typeof _closeBtn === "String" && !_closeBtn) { //如果是
                _closeBtn = 1;
            }

            var _title_text = jparam.title;
            var _title_style = 'border:0;height:auto;background:transparent;text-align:center;color:#006953;font-size:20px;font-weight:bold;';
            var _title;

            if (_title_text === false) {
                _title = false;

            } else if (Object.prototype.toString.call(_title_text) === '[object Array]' && _title_text[1]) {
                _title_style += _title_text[1];
                _title = [_title_text[0], _title_style];

            } else {
                _title_text = _title_text ? _title_text : '';
                _title = [_title_text, _title_style];
            }


            var _page_param = jparam.page_param ? jparam.page_param : '';
            var _page_param2 = _page_param;
            if ('' != _page_param) {
                _page_param = '&' + _page_param;
            }
            if (_page) {
                _url = 'wdk?action=ecw.page&method=display&site_id=' + _SITE_ID + '&inclient=' + _INCLIENT + '&win_id=' + _win_id + '&page_id=' + _page + _page_param;
            } else {
                _url = _url.match(/\?/) ? (_url + "&win_id=" + _win_id + _page_param) : (_url + '?win_id=' + _win_id + _page_param)
            }
            var _width = jparam.width;
            var _height = jparam.height;
            var _maximum = jparam.maximum || false;
            //		_width = _width.replace('px','');
            //		_height = _height.replace('px','');

            var _onSubmit = jparam.onSubmit ? jparam.onSubmit : function() {};
            var _onCancel = jparam.onCancel ? jparam.onCancel : function() {};

            var _mid_onSubmit = $.method_reg(window, _onSubmit);
            var _mid_onCancel = $.method_reg(window, _onCancel);

            _url = _url + '&mid_submit=' + _mid_onSubmit + '&mid_cancel=' + _mid_onCancel;
            //		关闭函数

            if (typeof jparam.close == "function") {
                var _closefn = jparam.close;
            }


            //		if (Object.prototype.toString.call(_title) === '[object Array]') {//如果是数组
            //
            //		}
            _win_id = $.getRoot().layer.open({
                type: 2,
                content: _url,
                area: [_width, _height],
                title: _title,
                cancel: _closefn,
                closeBtn: _closeBtn,
                move: _move,
                success: function(layero, index) {
                    //如果要求最大化窗口则调用窗口最大化方法
                    if (_maximum == true) {
                        $.getRoot().layer.full(index);
                    }
                }
            });

            return _win_id;

            //创建蒙版div
            /*
            var div_bg = document.createElement("DIV");
            div_bg.style.visibility = 'visible';
            div_bg.style.zIndex = 999997;
            div_bg.style.overflow = "hidden";
            div_bg.style.width = '100%';
            div_bg.style.height = '100%';
            div_bg.style.position = 'fixed';
            div_bg.style.left = '0px';
            div_bg.style.top = '0px';
            div_bg.style.backgroundColor = '#000000';
            div_bg.style.opacity = "0.5";
            document.body.appendChild(div_bg);
            */
            //		var html_bg = new Array();
            //		html_bg.push('<div name="designer_dlg" id="designer_dlg_'+_win_id+'" style="z-index:999997;visibility:visible;overflow:hidden;width:100%;height:100%;position:fixed;left:0px;top:0px;background-color:#000000;opacity:0.5;_position:absolute;_clear:both;"></div>');
            //
            //		var _top = $.getRoot();
            //		$(_top.document.body).append(html_bg.join(''));
            //
            //
            //
            //		var html = new Array();
            //		html.push(' <div name="designer_dlg" id="designer_dlg_'+_win_id+'_ifr" style="z-index:999998;overflow:hidden;position:fixed;left:50%;right:50%;top:50%;bottom:50%;width:'+_width+'px;height:'+_height+'px;margin-left:-'+_width/2+'px;margin-top:-'+_height/2+'px;');
            //		html.push('_position:absolute;_clear:both;_top:expression(eval(document.compatMode && document.compatMode=="CSS1Compat") ? documentElement.scrollTop + (documentElement.clientHeight-this.clientHeight) - 1 : document.body.scrollTop + (document.body.clientHeight-this.clientHeight) - 1);">');
            //		html.push('		<iframe id="" name="" src="'+_url+'"  width="100%" height="100%" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no" ></iframe>');
            //		html.push(' </div>');
            //		$(_top.document.body).append(html.join(''));
            //
            //		return _win_id;
            //		document.body.appendChild(html.join(''));

            /*
            //创建iframe居中背景
            var div_parent = document.createElement("DIV");
            div_parent.style.visibility = 'visible';
            div_parent.style.zIndex = 999998;
            div_parent.style.overflow = "hidden";
            //div_parent.style.width = _width;
            //div_parent.style.height = _height;
            div_parent.style.position = 'fixed';
            div_parent.style.left = '50%';
            div_parent.style.top = '50%';
            div_parent.style.bottom = '50%';
            div_parent.style.right = '50%';
            document.body.appendChild(div_parent);

            //创建iframe
            var div_ifr = document.createElement("DIV");
            div_ifr.style.visibility = 'visible';
            div_ifr.style.zIndex = 999999;
            div_ifr.style.overflow = "hidden";
            div_ifr.style.width = _width;
            div_ifr.style.height = _height;
            //div_parent.appendChild(div_ifr);

            div_parent.innerHTML = '<iframe id="" name="" src="'+_url+'"  width="'+_width+'" height="'+_height+'" style="margin-left:100px;" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no" ></iframe>';
            */
        }
        //关闭对话框的回调
        ,
    dialog_close: function(win_id) {
        var index = $.getRoot().layer.getFrameIndex(window.name); //先得到当前iframe层的索引
        $.getRoot().layer.close(index);

        //		layer.close(win_id);
        //		var _top = $.getRoot();
        //		$(_top.document.body).find("div[name='designer_dlg']").css('display','none');
        //		if(!win_id){
        //			win_id = $.getURLParam('win_id');
        //		}
        //		var _mid_submit = $.getURLParam('mid_submit');
        //		var _mid_cancel = $.getURLParam('mid_cancel');
        //		$.method_call(_mid_cancel,{});
        //		$(_top.document.body).find("div[name='designer_dlg']").remove();
    },
    dialog_submit: function(jresult, win_id) {
            var index = $.getRoot().layer.getFrameIndex(window.name); //先得到当前iframe层的索引
            var _mid_submit = $.getURLParam('mid_submit');
            var _mid_cancel = $.getURLParam('mid_cancel');
            $.method_call(_mid_submit, jresult);

            $.getRoot().layer.close(index);

            //		var _top = $.getRoot();
            //		$(_top.document.body).find("div[name='designer_dlg']").css('display','none');
            //		if(!win_id){
            //			win_id = $.getURLParam('win_id');
            //		}
            //		$(_top.document.body).find("div[name='designer_dlg']").remove();
        }
        //在浏览器新页签中打开
        ,
    dialog_open_innewtab: function(jparam) {
            var is_in_client = $.is_in_client();

            if (is_in_client) {
                $.dialog_open(jparam);
            } else {
                var _win_id = $.getUUID();
                var _page = jparam.page;
                var _newtabpage = jparam.newtabpage || '';
                var _url = jparam.url;

                var _page_param = jparam.page_param ? jparam.page_param : '';
                var _page_param2 = _page_param;
                if ('' != _page_param) {
                    _page_param = '&' + _page_param;
                }

                if (_newtabpage) {
                    _page = _newtabpage;
                }

                if (_page) {
                    _url = 'wdk?action=ecw.page&method=display&site_id=' + _SITE_ID + '&inclient=' + _INCLIENT + '&win_id=' + _win_id + '&page_id=' + _page + _page_param;
                } else {
                    _url = _url.match(/\?/) ? (_url + "&win_id=" + _win_id + _page_param) : (_url + '?win_id=' + _win_id + _page_param)
                }

                window.open(_url);
            }
        }
        //获取当前登录用户json对象
        ,
    getSessionUser: function() {
            var juser = new Object();
            juser.id = '';
            return juser;
        }
        //跳转到卷烟列表
        ,
    ciga_list: function(condition) {
        /*
        var jcondi = {
        	company_ids:'111,222'
        	,company_names:'哈哈，额呵呵'
        	,pinpai_ids:''
        	,pinpai_names:''
        	,price_low_id:''
        	,price_low_name:''
        	,price_high_id:''
        	,price_high_name:''
        	,label_ids:''
        	,label_names:''
        }
        */
        condition = Base64.encode($.json2str(condition));
        $.page_redirect('page_cigalist', 'condition=' + condition);

    },
    //	附件下载
    filedownloader: function(jparam) {
        var _url = jparam.url ? jparam.url : 'wdk?action=wdk.pub&method=attachment_download&ajaxparam=' + new Date().getTime();
        var _fileid = jparam.fileid;
        if (-1 == _url.indexOf('http')) {
            _url = $.base() + "/" + _url;
        }
        if (_fileid) {
            if (_url.indexOf("?") > 0) {
                _url += "&fileid=" + _fileid;
            } else {
                _url += "?fileid=" + _fileid;
            }
        }

        var oDiv = document.getElementById('wdk_download_div');
        if (!oDiv) {
            oDiv = document.createElement("DIV");
            oDiv.id = 'wdk_download_div';
            oDiv.style.visibility = 'visible';
            oDiv.style.zIndex = -999999;
            oDiv.style.overflow = "hidden";
            oDiv.style.width = '0px';
            oDiv.style.height = '0px';
            document.body.appendChild(oDiv);
        }
        var ifr = $('<iframe width="0px" height="0px" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>').appendTo($(oDiv));
        if (_url.length > 2000) {
            var insid = $.getUUID();
            var form = $('<form method="post"></form>').appendTo($(oDiv));
            form.hide();
            form.attr("id", "form" + insid);
            form.attr("target", "ifr" + insid);
            var rurl = _url.substring(0, _url.indexOf("?"));
            form.attr("action", rurl);
            var pstr = _url.substr(_url.indexOf("?") + 1);
            var parr = pstr.split("&");
            for (var i = 0; i < parr.length; i++) {
                var pp = parr[i].split("=");
                var ipt = $("<input>").appendTo(form);
                ipt.attr("name", pp[0]);
                ipt.val(decodeURIComponent(pp[1]));
            }
            //oDiv.innerHTML = '<iframe src="'+_url+'" width="0px" height="0px" frameborder="no" border="0" marginwidth="0" marginheight="0" scrolling="no"></iframe>';
            ifr.attr("id", "ifr" + insid);
            ifr.attr("name", "ifr" + insid);
            form[0].submit();
        } else {
            ifr.attr("src", _url);
        }
    },
    export_excel: function(jparam) {
        var _url = 'wdk?action=ecw.page&method=export_excel';

        var _title = jparam.title ? jparam.title : '';
        //var _columns = jparam.columns?jparam.columns:$.json2str([]);
        var _gridcode = jparam.gridcode ? jparam.gridcode : '';
        var _queryParams = jparam.data ? jparam.data : $.json2str({});

        _queryParams.eptitle = _title;
        _queryParams.epgridcode = _gridcode;
        //_queryParams.epcolumns = _columns;

        var _param = "wppm=" + Base64.encode2(escape($.json2str(_queryParams)));

        _url += "&" + _param;

        $.filedownloader({
            url: _url
        });
    },
    base: function() {
        if ($("base").length > 0) {
            var b = $("base").attr("href");
            return b.substring(0, b.length - 1);
        }
        var urlstr = document.location.href;
        if (urlstr.indexOf("http") != -1) {
            var reg = /http:\/\/[^\/]*/g;
            var httpurl = reg.exec(urlstr) + "";
            var str1 = urlstr.replace(/http:\/\//g, "");
            var reg = /[^\/]*\/[^\/]*/g;
            var str2 = reg.exec(str1) + "";
            var appname = str2.replace(/[^\/]*\//g, "");
            return httpurl + "/" + appname;
        } else {
            return "";
        }
    },
    //密码长度要求8位及以上，且至少包含字母、数字两种；
    test_web: function(pwdStr) {
        var reg1 = /^.*[0-9].*$/;
        var reg2 = /^.*[a-zA-Z].*$/;

        var num = 0;
        if (reg1.test(pwdStr)) {
            num++;
        }
        if (reg2.test(pwdStr)) {
            num++;
        }

        if (num != 2) {
            return false;
        }
        if (pwdStr.length < 8) {
            return false;
        }
        return true;
    }

});


/***********************************************************/
/****													****/
/****					ALERT							****/
/****													****/
/****													****/
/***********************************************************/
window.alert = function(msg, callback) {
    if (typeof callback == "function") {
        layer.alert(msg, {
            closeBtn: 0
        }, function(index) {
            callback(index);
        });
    } else {
        layer.alert(msg, {
            closeBtn: 0
        });
    }

}


/***********************************************************/
/****													****/
/****					TRIM							****/
/****													****/
/****													****/
/***********************************************************/
if (typeof String.prototype.trim !== 'function') {
    String.prototype.trim = function() {
        return this.replace(/^\s\s*/, '').replace(/\s\s*$/, '');
    }
}


/***********************************************************/
/****													****/
/****					CONSOLE							****/
/****													****/
/****													****/
/***********************************************************/
if (typeof(console) == "undefined") {
    window.console = {
        log: function() {},
        debug: function() {}
    }
}

function loadScript(url, callback) {
    var script = document.createElement('script');
    script.type = 'text/javascript';
    script.src = url;
    script.onreadystatechange = function() {
        if (script.readyState === 'complete' || script.readyState === 'loaded') {
            script.onreadystatechange = null;
            callback();
        }
    };
    script.onload = callback;
    document.head.appendChild(script);
}